home *** CD-ROM | disk | FTP | other *** search
/ Sprite 1984 - 1993 / Sprite 1984 - 1993.iso / src / cmds / cvs / sprite / save / version_ts.c < prev   
C/C++ Source or Header  |  1991-07-29  |  3KB  |  137 lines

  1. #ifndef lint
  2. static char rcsid[] = "$Id: version_ts.c,v 1.1 91/07/11 18:05:50 jhh Exp Locker: jhh $";
  3. #endif !lint
  4.  
  5. /*
  6.  *    Copyright (c) 1989, Brian Berliner
  7.  *
  8.  *    You may distribute under the terms of the GNU General Public License
  9.  *    as specified in the README file that comes with the CVS 1.0 kit.
  10.  *
  11.  * Version and Time Stamp
  12.  *
  13.  *    Sets the following global variables:
  14.  *    VN_User        version # of the RCS file the user file derives from;
  15.  *            may also be:
  16.  *                empty:        no entry for user file
  17.  *                0:        user file is new
  18.  *                -$VN_User:    user file is to be removed
  19.  *    VN_Rcs        version # of active RCS file
  20.  *                is empty for absent RCS file
  21.  *    TS_User        present time stamp of the user file
  22.  *                is empty for absent user file
  23.  *    TS_Rcs        time stamp of the lastest check-out of the RCS file.
  24.  *
  25.  *    The syntax of an entry is
  26.  *        <version-number>|<time-stamp>|
  27.  *    and the time-stamp currently includes the file change and modify 
  28.  *    times as well as the User file name.
  29.  */
  30.  
  31. #include <sys/types.h>
  32. #include <sys/timeb.h>
  33. #include <sys/stat.h>
  34. #include <ctype.h>
  35. #include <grp.h>
  36. #include <pwd.h>
  37. #include <utmp.h>
  38. #include "cvs.h"
  39.  
  40. /*
  41.  * "rcs" is the full pathname to the ,v file; "user" is the name of
  42.  * the local file.
  43.  */
  44. Version_TS(rcs, tag, user)
  45.     char *rcs;
  46.     char *tag;
  47.     char *user;
  48. {
  49.     FILE *fpin;
  50.     char line[MAXLINELEN];
  51.     char *cp;
  52.     int found = 0;
  53.  
  54.     /*
  55.      * Get RCS version number in VN_Rcs
  56.      */
  57.     Version_Number(rcs, tag, Date, VN_Rcs);
  58.     time_stamp(user, TS_User);        /* get time-stamp in TS_User */
  59.     /*
  60.      * Now read through the "Entries" file to find the
  61.      * version number of the user file, and the time-stamp
  62.      * of the RCS file
  63.      */
  64.     fpin = open_file(CVSADM_ENT, "r");
  65.     while (fgets(line, sizeof(line), fpin) != NULL) {
  66.     if ((cp = rindex(line, '|')) == NULL)
  67.         continue;
  68.     *cp = '\0';
  69.     if ((cp = rindex(line, ' ')) == NULL)
  70.         continue;
  71.     cp++;
  72.     if (strcmp(user, cp) == 0) {
  73.         found = 1;
  74.         break;
  75.     }
  76.     }
  77.     if (found) {
  78.     if ((cp = index(line, '|')) != NULL) {
  79.         *cp++ = '\0';
  80.         (void) strcpy(VN_User, line);
  81.         (void) strcpy(TS_Rcs, cp);
  82.     } else {
  83.         VN_User[0] = '\0';
  84.         TS_Rcs[0] = '\0';
  85.     }
  86.     } else {
  87.     VN_User[0] = '\0';
  88.     TS_Rcs[0] = '\0';
  89.     }
  90.     (void) fclose(fpin);
  91. }
  92.  
  93. /* Some UNIX distributions don't include these in their stat.h */
  94. #ifndef S_IWRITE
  95. #define    S_IWRITE    0000200        /* write permission, owner */
  96. #endif !S_IWRITE
  97. #ifndef S_IWGRP
  98. #define    S_IWGRP        0000020        /* write permission, grougroup */
  99. #endif !S_IWGRP
  100. #ifndef S_IWOTH
  101. #define    S_IWOTH        0000002        /* write permission, other */
  102. #endif !S_IWOTH
  103.  
  104. /*
  105.  * Gets the time-stamp for the file "file" and puts it in the already
  106.  * allocated string "ts".
  107.  *
  108.  * As a side effect, if the user wants writable files and the file
  109.  * currently has no write bits on, the file is made writable now.
  110.  */
  111. static
  112. time_stamp(file, ts)
  113.     char *file;
  114.     char *ts;
  115. {
  116.     struct stat sb;
  117.     char *ctime();
  118.     char *cp;
  119.  
  120.     if (lstat(file, &sb) < 0) {
  121.         ts[0] = '\0';
  122.     } else {
  123.     if (cvswrite == TRUE &&
  124.         (sb.st_mode & (S_IWRITE|S_IWGRP|S_IWOTH)) == 0) {
  125.         xchmod(file, 1);
  126.         (void) stat(file, &sb);
  127.     }
  128.     cp = ctime(&sb.st_ctime);
  129.     cp[24] = ' ';
  130.     (void) strcpy(ts, cp);
  131.     cp = ctime(&sb.st_mtime);
  132.     cp[24] = ' ';
  133.     (void) strcat(ts, cp);
  134.     (void) strcat(ts, file);
  135.     }
  136. }
  137.